package com.exam.springbootexam.service.impl;
import com.exam.springbootexam.entity.PageEntity;
import com.exam.springbootexam.entity.Student;
import com.exam.springbootexam.mapper.StudentMapper;
import com.exam.springbootexam.service.StudentService;
//import jakarta.annotation.Resource;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 十五
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentMapper studentMapper;

    /**
     * 分页查询学生
     *
     * @param current  当前页码
     * @param pageSize 总数
     * @return pageEntity
     */
    @Override
    public PageEntity<Student> selectByPage(Integer current, Integer pageSize) {
        //查询总数
        int total = studentMapper.selectCont();
        //分页查询数据
        List<Student> users = studentMapper.selectLimit((current - 1) * pageSize, pageSize);
        PageEntity<Student> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(users);
        return pageEntity;
    }

    /**
     * 查询所有学生
     *
     * @return List<Student>
     */
    @Override
    public List<Student> selectAll() {
        return studentMapper.selectAll();
    }

    /**
     * 按studentId查询学生
     *
     * @param studentId String
     * @return Student
     */
    @Override
    public Student selectById(Integer studentId) {
        return studentMapper.selectById(studentId);
    }

    /**
     * 按name查询学生
     *
     * @param name String 学生姓名
     * @return Student
     */
    @Override
    public Student selectByName(String name) {
        return studentMapper.selectByName(name);
    }

    /**
     * 按classId查询学生
     *
     * @param classId Integer 班级id
     * @return Student
     */
    @Override
    public Student selectByClassId(Integer classId) {
        return null;
    }

    /**
     * 模糊查询
     *
     * @param keyword String
     * @return List<Student>
     */
    @Override
    public List<Student> serachByKeyword(String keyword) {
        return studentMapper.search(keyword);
    }

    /**
     * 添加学生
     *
     * @param student Student
     * @return boolean
     */
    @Override
    public boolean add(Student student) {
        return studentMapper.add(student);
    }

    /**
     * 删除学生
     *
     * @param studentId String
     * @return boolean
     */
    @Override
    public boolean delete(Integer studentId) {
        return studentMapper.delete(studentId);
    }

    /**
     * 更新学生
     *
     * @param student Student
     * @return boolean
     */
    @Override
    public boolean update(Student student) {
        return studentMapper.update(student);
    }
}
